//*****************************************************************************
// JFab (http://code.google.com/p/jfab)
// Copyright (c) 2011-2012 JFab.org
// Admin jfab@jeffreythompson.net
//
// See the file "LICENSE.txt" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//*****************************************************************************

package org.jfab.swingui.editpane;

import javax.swing.JTextArea;

import org.jfab.core.model.CGInterface;

/**
 * Provides an edit pane for a code generator interface.
 */
public final class CGInterfaceEditPane extends
        CGCompilationUnitEditPane<CGInterface>
{
    /** Serial version UID. */
    private static final long serialVersionUID = 1L;

    /** Extends types widget. */
    private JTextArea _extendsTypesUI;

    /**
     * Construct this object with the given parameter.
     * 
     * @param cgInterface Code generator interface.
     */
    public CGInterfaceEditPane(final CGInterface cgInterface)
    {
        super(cgInterface);
    }

    @Override
    public final void applyChanges()
    {
        super.applyChanges();

        final CGInterface subject = getSubjectObject();

        subject.getExtendsTypes().clear();
        subject.getExtendsTypes().addAll(
                getCgTypeListAdapter().unmarshal(_extendsTypesUI.getText()));
    }

    @Override
    protected final void createWidgets()
    {
        super.createWidgets();

        _extendsTypesUI = createTextArea();
    }

    @Override
    protected final void fillPanel()
    {
        // Custom layout to resemble the code view.
        bindAndAdd("title", _titleUI);
        bindAndAdd("class", _classUI);
        bindAndAdd("packageName", _packageNameUI);
        bindAndAdd("referencedTypes", _referencedTypesUI,
                getCgTypeListAdapter());
        bindAndAdd("commentLines", _commentLinesUI, getStringListAdapter());
        bindAndAdd("annotations", _annotationsUI, getCgAnnotationListAdapter());
        bindAndAdd("modifiers", _modifiersUI, getStringListAdapter());
        bindAndAdd("name", _nameUI);
        bindAndAdd("typeParameters", _typeParametersUI, getStringListAdapter());
        bindAndAdd("extendsTypes", _extendsTypesUI, getCgTypeListAdapter());
        bindAndAdd("propertyChangeSupported", _propertyChangeSupportedUI);
    }

    @Override
    protected final void fillWidgets()
    {
        super.fillWidgets();

        final CGInterface subject = getSubjectObject();

        _extendsTypesUI.setText(getCgTypeListAdapter().marshal(
                subject.getExtendsTypes()));
    }
}
